{% extends 'base.html' %}
{% load static %}
{% block title %}学生管理{% endblock %}
{% block extra_css %}{% endblock %}
{% block modal %}
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">学生创建</h4>
            </div>
            <div class="modal-body">
                <div style="width:100%;padding: 10px 20px 10px 20px">
                    <form id="cs_form">
                        {% csrf_token %}
                        学号: <input name="stu_id" type="number" min="1" max="999999999999999"> <br>
                        姓名: <input name="stu_name" type="text"> <br>
                        性别: <input type="radio" name="sex" value=0 />男
                        <input type="radio" name="sex" value=1 />女 <br>
                        班级: <input name="depart" type="number" min="1" max="9999"> <br>
                        专业: <input name="major" type="text"> <br>
                        入学年份: <input name="en_year" type="number" min="2000" max="3000"> <br>
                        修学年限: <input name="school_year" type="number" min="1" max="8"> <br>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button id="cs_sub" type="button" class="btn btn-primary">创建</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block stu_manager %}active{% endblock %}
{% block modal_button %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
    学生创建
</button>
{% endblock %}
{% block table_title %}<h3>学生列表</h3>{% endblock %}
{% block table_content %}
<thead>
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>专业班级</th>
        <th>关联账号</th>
        <th>操作</th>
    </tr>
</thead>
<tbody>


    {% if stus_list %}
    {% for stu in stus_list %}
    <tr>
        <td>{{ stu.student_ID }}</td>
        <td>{{ stu.name }}</td>
        <td>{% if stu.sex is False %}男{% else %}女{% endif %}</td>
        <td>{{ stu.enroll_year }}级{{ stu.major }}{{ stu.department }}班</td>
        <td>{{ stu.account_status }}</td>
        <td>
            <!-- <a class="btn btn-default btn-xs" href="#" style="margin-top:0">修改</a>  -->
            <a class="btn btn-default btn-xs" href="{% url 'dashboard:stu_info' stu.student_ID  %}"
                >详情</a>
            <a class="btn btn-danger btn-xs" href="{% url 'dashboard:delete_student' stu.student_ID  %}"
                >删除</a>
        </td>
    </tr>
    {% endfor %}
    {% else %}
    <tr>
        <td>无数据</td>
    </tr>
    {% endif %}
    <!-- <tr>
      <td>&nbsp</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td>&nbsp</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr> -->
</tbody>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
    // $('#datetimepicker0').datetimepicker();
    // $('#datetimepicker1').datetimepicker();

    function sub(sub_btn, sub_form, red_url) {
        $(sub_btn).click(function () {
            $.ajax({
                type: 'post',
                dataType: 'html',
                url: red_url,
                data: $(sub_form).serialize(),
                contentType: "application/x-www-form-urlencoded",
                success: function (data) {
                    alert(data)
                    location.replace('/dashboard/stu_manager/')
                }
            })
        })
    }

    sub('#cs_sub', '#cs_form', '/dashboard/create_student/')
</script>
{% endblock %}